package com.example.mdc.logback.common.config.canal;

import com.alibaba.otter.canal.client.CanalConnector;
import com.alibaba.otter.canal.client.CanalConnectors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import java.net.InetSocketAddress;

/**
 * @author:      liu_pc
 * Date:        2023/8/25
 * Description: Canal配置类
 * Version: 1.0
 */
@Configuration
public class CanalConfig {

    @Value("${canal.server.host}")
    private String canalServerHost;

    @Value("${canal.server.port}")
    private int canalServerPort;

    @Value("${canal.server.destination}")
    private String canalDestination;

    @Value("${canal.server.username}")
    private String canalUsername;

    @Value("${canal.server.password}")
    private String canalPassword;

    @Bean
    @DependsOn("dataSource")
    public CanalConnector canalConnector() {
        return CanalConnectors.newSingleConnector(
                new InetSocketAddress(canalServerHost, canalServerPort),
                canalDestination,
                canalUsername,
                canalPassword
        );
    }

}
